package dk.isten.andro.main;

import java.io.File;
import java.util.ArrayList;

import util.CostumBaseAdapterStilling;
import util.Item;
import util.ReadWrite;
import util.XMLParsingStilling;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import dk.isten.andro.R;

public class Stilling_List_Akt extends SuperActivity implements OnClickListener{
    /** Called when the activity is first created. */
	ArrayList<Item> items;
	ImageView roed, horn,gul, spiller_img, imageView1;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.stilling_holder);
        
        gul = (ImageView) findViewById(R.id.yellow);
        horn = (ImageView) findViewById(R.id.horn);
        roed = (ImageView) findViewById(R.id.red);
        imageView1 = (ImageView) findViewById(R.id.imageView1);
		
		imageView1.setOnClickListener(this);
        gul.setOnClickListener(this);
        horn.setOnClickListener(this);
        roed.setOnClickListener(this);
       


        String filnavn = "stilling.xml";
        String url = "http://andro.isten.dk/stadionapp/tmp/index.php?poolid=149819"; //URL skal hentes fra Stamdata 
     	File directory = new File(Environment.getExternalStorageDirectory(), "/StadionApp" );
     	directory.mkdirs();
    	File file = new File(directory, filnavn );
    	
    	Log.d("path", " " + file );

    	if(file.exists()==false){
    		
    		ReadWrite.init(url, filnavn);
    	}
        	XMLParsingStilling XMLP = new XMLParsingStilling();
        	items = XMLP.StillingParser(file);
//        	Log.d("fra items",items.size() + "");
//        	Log.d("fra items",items.get(1).getName());
        
        final ListView lv1 = (ListView) findViewById(R.id.ListView01);
        lv1.setAdapter(new CostumBaseAdapterStilling(this, items));

    }
	@Override 
	public void onClick(View v) {

if(v==imageView1){
            
        	Intent i = new Intent(this, FrontActivity.class);
           
                    startActivity(i);
                    
        }else if(v==gul){
                
                	Intent i = new Intent(this, yellow.class);
                   
                            startActivity(i);
                            
                }else if(v==roed){
                	Intent i = new Intent(this, red.class);
                    
                    		startActivity(i);
                }else if(v==horn){
                	
                	MediaPlayer enLyd = MediaPlayer.create(this, R.raw.vuvuzela);
                    enLyd.setVolume(9, 9);
                    enLyd.start();
        }
                }
	


	
//    public void OpdaterListView(){
//    	final ListView lv1 = (ListView) findViewById(R.id.ListView01);
//        lv1.setAdapter(new CostumBaseAdapter(this, items));
//    }
    //hvis jeg på et tidspunkt vil have noget afsluttende handling på min AsyncTask er det her jeg skal skrive det
    
//    private BroadcastReceiver stillingOpdateret = new BroadcastReceiver() {
//		@Override
//		public void onReceive(Context ctx, Intent i) {
//			android.util.Log.d("baggrundsproces", "stillingens opdateres");
////			OpdaterListView();
//		}
//	};
	
}